package com.xingshentech.ugv.operate.module.listener;

import android.view.View;

/**
 * Created by Administrator on 2018/8/8.
 * 避免重复点击
 */

public abstract class OnMultiClickListener implements View.OnClickListener {
    // 两次点击按钮之间的点击间隔不能少于1000毫秒
    private static final int MIN_CLICK_DELAY_TIME = 500;
    private static long lastClickTime;//static 保证每次点击都会修改

    public abstract void onMultiClick(View v);

    @Override
    public void onClick(View v) {
        long currentTime = System.currentTimeMillis();

        if ((currentTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间

            onMultiClick(v);
        }
        lastClickTime = currentTime;
    }
}
